export const containsArray = (str) => {
  const arrayRegex = /^\[.*\]$/; // 正则表达式，匹配以[开头和]结尾的字符串
  const jsonRegex = /^\[.*\]$/; // 正则表达式，匹配有效的JSON数组格式
  const matches = str.match(arrayRegex);
  return matches !== null && jsonRegex.test(str);
}
export const isNumeric = (str) =>{
  return /^\d+$/.test(str);
}
export const isIncludeStr = (targetStr, str) => {
  return targetStr.includes(str);
}

const dataType = ['textarea', 'input', 'time', 'rate', 'rich-editor', 'switch', 'date-range', 'time-range', 'select', 'check-box', 'number', 'radio']
export const findWidgetListInData = (data) => {
  let result: any = [];
  function traverse(obj) {
    if (Array.isArray(obj)) {
      obj.forEach(item => {
        traverse(item);
      });
    } else if (typeof obj === 'object') {
      if (obj) {
				if (Array.isArray(obj.widgetList)) {
					result = [...result, ...obj.widgetList]
				}
      }
      for (const key in obj) {
        traverse(obj[key]);
      }
    }
  }
  data.forEach(item => {
    if (filterData(item)) {
      result.push(item)
    } else {
      traverse(item)
    }
  });
  return result;
}
function filterData(data: any) {
  const res = dataType.some(val => {
    return val === data.type
  })
  return res
}
const imgType = ['png', 'jpg', 'jpeg', 'gif', 'PNG', 'JPEG', 'JPEG', 'GIF']
export const imgCheck = (str) => {
  const checkRes = imgType.some(val => {
    return str.includes(val)
  })
  return checkRes
}
